﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CourseSelectionSystem
{
    public partial class EditTeacher : Form
    {
        private readonly CourseSelectionSystemServices services = new CourseSelectionSystemServices();

        //记录当前ID
        private string ID;
        public EditTeacher()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 从上级窗体导入ID
        /// </summary>
        /// <param name="ID"></param>
        public EditTeacher(string ID)
        {
            InitializeComponent();
            var item = services.GetBytID(ID);
            if (item != null)
            {
                textID.Text = item.ID;
                textName.Text = item.Name;
                textTitle.Text = item.Title;
                textPassword.Text = item.Password;
                this.ID = ID;
            }
        }

        /// <summary>
        /// 保存操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            EditModelt modelt = new EditModelt()
            {
                ID = this.ID,
                Name = textName.Text,
                Title = textTitle.Text,
                Password = textPassword.Text,
            };
            services.Editt(modelt);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        /// <summary>
        /// 取消操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void EditTeacher_Load(object sender, EventArgs e)
        {

        }

        public bool SaveChanges()
        {
            return true;
        }
    }
}
